# -*- coding: utf-8 -*-

from __future__ import print_function
import logging

import grpc
from helloworld_pb2 import HelloRequest, HelloReply
from helloworld_pb2_grpc import HelloWorldServiceStub

def run():
  # 使用with语法保证channel自动close
  with grpc.insecure_channel('localhost:50000') as channel:
    # 客户端通过stub来实现rpc通信
    stub = HelloWorldServiceStub(channel)

    # 客户端必须使用定义好的类型，这里是HelloRequest类型
    response = stub.SayHello(HelloRequest(name='zongxp'))
  print ("hello client received: " + response.message)

if __name__ == "__main__":
  logging.basicConfig()
  run()